package net.zjitc.service.Impl;

import net.zjitc.mapper.CategoryMapper;
import net.zjitc.pojo.Category;
import net.zjitc.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public void addCategory(Category category) {
        categoryMapper.addCategory(category);
    }

    @Override
    public List<Category> findCategoryList() {
        List<Category> categoryList = categoryMapper.findCategoryList();
        for (int i = 0; i < categoryList.size(); i++) {
            Category category = categoryList.get(i);
            int pid = category.getPid();
            if(pid!=0) {
                for(Category category1:categoryList){
                    if(category1.getId()==pid){
                        category.setPname(category1.getName());
                    }
                }
            }
            
        }
        return categoryList;
    }

    @Override
    public void deleteCategory(int id) {
        categoryMapper.deleteCategory(id);
    }

    @Override
    public void updateCategory(Category category) {
        categoryMapper.updateCategory(category);

    }
}
